import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:industry_net/base/common/colors_util.dart';
import 'package:industry_net/base/common/img_util.dart';
import 'package:industry_net/base/common/size_fit.dart';
import 'package:industry_net/base/common/text_util.dart';
import 'package:industry_net/pages/me/main/models/usually.dart';

showDropDown({
  required GlobalKey key,
  required List<UsuallyModel> list,
  required Function(int)? onTap,
}) {
  var robj = key.currentContext?.findRenderObject() as RenderBox?;
  if (robj == null) {
    return;
  }
  Get.log(robj.size.height.toString());
  var offset = robj.localToGlobal(Offset(robj.size.width, robj.size.height));
  showCupertinoDialog(
      context: Get.context!,
      barrierDismissible: true,
      builder: (context) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            Container(
              margin: EdgeInsets.only(top: offset.dy, right: gap12),
              width: 160.w,
              decoration: BoxDecoration(
                  color: ColorsUtil.white,
                  borderRadius: BorderRadius.circular(circle4)),
              child: Column(
                children: list
                    .map(
                      (e) => Container(
                        padding: EdgeInsets.symmetric(horizontal: gap12),
                        height: buttonHeight,
                        decoration: UnderlineTabIndicator(
                            insets: EdgeInsets.symmetric(horizontal: gap12),
                            borderSide: const BorderSide(
                                width: 1, color: ColorsUtil.separator)),
                        child: Row(
                          children: [
                            Visibility(
                              child: e.iconData != null
                                  ? Icon(
                                      e.iconData,
                                      size: 24.r,
                                    )
                                  : e.url != null
                                      ? loadImage(
                                          url: e.url,
                                          width: 24.r,
                                          height: 24.r,
                                          fit: BoxFit.contain)
                                      : const SizedBox(),
                            ),
                            Text(
                              e.name,
                              style: pfMediumStyle(
                                  color: ColorsUtil.title, fontSize: font15),
                            )
                          ],
                        ),
                      ),
                    )
                    .toList(),
              ),
            ),
          ],
        );
      });
}
